/*
 * Copyright (C) 2012-2013 Matthias Zeimer and the miniframes project group.
 * All rights reserved. 
 * 
 * Licensed under the Eclipse Public License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.opensource.org/licenses/EPL-1.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package de.miniframes.minivalues;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * <p>
 * A utility to inspect sub-classes of {@link Value}.
 * </p>
 * 
 * @author Matthias Zeimer
 * @version 1
 * @since 0.1, 19.01.2013
 */
final class ReflectionUtil {

    /**
     * <p>
     * Returns the {@link Class} assigned to the type-argument {@code T} of
     * class {@link Value}.
     * </p>
     * 
     * @param classToInspect
     *            The value class to inspect, not <code>null</code>.
     * @return The value of values type-argument {@code T}, not
     *         <code>null</code>.
     * @throws NullPointerException
     *             if {@code classToInspect} is <code>null</code>.
     */
    public static Class<?> getValueTypeArguement(
            final Class<? extends Value<?>> classToInspect) {
        // DRAFT:
        final Type genericSuperclass = classToInspect.getGenericSuperclass();
        final ParameterizedType pt = (ParameterizedType) genericSuperclass;
        // Type rawType = pt.getRawType();
        final Type[] actualTypeArguments = pt.getActualTypeArguments();
        final Type typeVariable = actualTypeArguments[0];
        return (Class<?>) typeVariable;
    }

    private ReflectionUtil() {
        // Avoid instances.
    }

}
